package com.xiaobai.excel.handler;

import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import org.apache.poi.ss.usermodel.Row;

/**
 * 设置表头的自动调整行高策略
 */
public class CellRowHeightStyleStrategy extends AbstractRowHeightStyleStrategy {


    private final Integer titleHeight;
    private final Integer columnHeight;

    public CellRowHeightStyleStrategy(Integer titleHeight, Integer columnHeight) {
        this.titleHeight = titleHeight;
        this.columnHeight = columnHeight;
    }

    @Override
    protected void setHeadColumnHeight(Row row, int relativeRowIndex) {

        if (titleHeight != null) {
            row.setHeight((short) (titleHeight * 20));
            return;
        }

        if(relativeRowIndex == 0){
            //如果excel需要显示行高为15，那这里就要设置为15*20=300
            row.setHeight((short) 400);
        }
    }

    @Override
    protected void setContentColumnHeight(Row row, int relativeRowIndex) {
        if (columnHeight != null) {
            row.setHeight((short) (columnHeight * 20));
            return;
        }
        row.setHeight((short) 400);
    }
}